<template>
  <div id="app">
    <router-view />
    <theme-picker />
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";
import { listConfig } from '@/api/system/config'

export default {
  name: "App",
  components: { ThemePicker },
  metaInfo() {
    return {
      title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
      titleTemplate: title => {
        return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
      }
    }
  },
  created() {
    this.listConfig();
  },
  mounted() {
    setTimeout(() => {
      this.a()
    }, 2000);
    window.onload = function () {
      document.body.style.zoom = "90%";
    }


    // 覆盖ctrl||command + ‘+’/‘-’
    // document.onkeydown = function (event) {
    //   const e = event || window.event;
    //   const ctrlKey = e.ctrlKey || e.metaKey;
    //   if (ctrlKey && keyCodeMap[e.keyCode]) {
    //     e.preventDefault();
    //   } else if (e.detail) { // Firefox
    //     event.returnValue = false;
    //   }
    // };
    // // 覆盖鼠标滑动
    // document.body.addEventListener('wheel', (e) => {
    //   if (e.ctrlKey) {
    //     if (e.deltaY < 0) {
    //       e.preventDefault();
    //       return false;
    //     }
    //     if (e.deltaY > 0) {
    //       e.preventDefault();
    //       return false;
    //     }
    //   }
    // }, { passive: false });


    // this.bodyScale();
    // window.addEventListener("resize", this.bodyScale, false);
  },
  methods: {
    a() {
      //获取页面上.nest-menu下面的span标签
      // 获取所有具有类名 "nest-menu" 的元素
      var nestMenus = document.getElementsByClassName("nest-menu");

      // 遍历所有具有类名 "nest-menu" 的元素
      for (var i = 0; i < nestMenus.length; i++) {
        // 获取当前元素下的所有 span 标签
        var spanElements = nestMenus[i].getElementsByTagName("span");

        // 遍历所有找到的 span 标签
        for (var j = 0; j < spanElements.length; j++) {
          var maxLength = 6; // 设定文本最大长度为 6

          // 如果文本长度超过 maxLength，则截取文本并添加省略号
          if (spanElements[j].textContent.length > maxLength) {
            var truncatedText = spanElements[j].textContent.substring(0, maxLength) + "...";
            spanElements[j].textContent = truncatedText;

            // 获取父元素 el-menu-item 并为其添加样式
            // var parentElMenuItem = spanElements[j].closest(".el-menu-item");
            // if (parentElMenuItem) {
            //   parentElMenuItem.style.overflow = "hidden";
            //   parentElMenuItem.style.setProperty("overflow", "hidden", "important");
            // }
          }
        }
      }
    },
    bodyScale() {
      var deviceWidth = document.documentElement.clientWidth; //获取当前分辨率下的可是区域宽度
      var scale = deviceWidth / 1410; // 分母——设计稿的尺寸
      if (deviceWidth > 1410) {
        scale = 1;
      } else {
        document.documentElement.style.zoom = scale; //放大缩小相应倍数
        // scale = 1;

      }
    },
    listConfig() {
      listConfig({
        configName: '系统ico'
      }).then(res => {
        //修改hmtl的ico
        let link = document.querySelector("link[rel*='icon']") || document.createElement('link');
        link.type = 'image/x-icon';
        link.rel = 'shortcut icon';
        link.href = process.env.VUE_APP_BASE_API + res.rows[0].configValue;
        document.getElementsByTagName('head')[0].appendChild(link);
      })
    }
  }
};
</script>
<style scoped>
#app .theme-picker {
  display: none;
}

@media (max-width: 1920px) and (min-width: 768px) {
  html {
    zoom: 90%;
  }

  @-ms-viewport {
    width: 1920px;
  }
}
</style>
